<?php
/**
 * FileName: SystemSettingBasicForm.php
 * Author: 790213952@qq.com
 * DateTime: 2024/8/7 下午12:34
 * SystemName: Ymtc
 *
 */


/**
 * FileName: SiteConfig.php
 * Author: Xiao Yao <790213952@qq.com>
 * DateTime: 2022-09-15 下午 02:23
 * Summary:
 */


namespace YmPhp\Admin\Http\Forms;


use YmPhp\Admin\Models\Setting as SystemSettingModel;
use YmPhp\Admin\Widgets\Form;
use Illuminate\Http\Request;

class SystemSettingBasicForm extends Form
{
    /**
     * The form title.
     *
     * @var string
     */
    public $title = '基本设置';

    /**
     * Handle the form request.
     *
     * @param Request $request
     *
     */
    public function handle(array $input)
    {
        (new SystemSettingModel())->saveConfig($input,'system_basic');
        return $this->response()->success('保存成功');
    }

    /**
     * Build a form here.
     */
    public function form()
    {

        $this->tab(trans('setting.basic.basic_settings'), function () {
            $this->text('title', trans('setting.basic.site_title'));
            $this->text('basehost', trans('setting.basic.site_basehost'))->icon('icon-link');
            $this->image('logo', trans('setting.basic.site_logo'))->autoUpload()->uniqueName()->saveFullUrl();
            $this->textarea('description', trans('setting.basic.site_description'));
            $this->textarea('keywords', trans('setting.basic.site_keywords'));
            $this->radio('map', trans('setting.basic.site_map'))
                ->when(1, function (Form $form) {
                    $this->text('baidu_js_ak', trans('setting.basic.site_baidu_js_ak'));
                    $this->text('baidu_ak', trans('setting.basic.site_baidu_ak'));
                })
                ->when(2, function (Form $form) {
                    $this->text('qqlbs', trans('setting.basic.site_qqlbs'));
                })->options(['0' =>  trans('setting.basic.close'), '1' => trans('setting.basic.whole_baidu'), '2' =>  trans('setting.basic.whole_tencent')])->default('0');

            $this->list('hotline', trans('setting.basic.site_hotline'));
            $this->text('400', trans('setting.basic.site_400'));
            $this->textarea('beian', trans('setting.basic.site_beian'));
            $this->textarea('powerby', trans('setting.basic.site_powerby'));
            $this->radio('visitState', trans('setting.basic.site_visit_state'))
                ->when(2, function (Form $form) {
                    $this->textarea('visitStateMsg', trans('setting.basic.site_visit_state_msg'))->help(trans('setting.basic.site_visit_state_msg_tip'));
                })->options(['1'=>trans('setting.basic.open'),'2'=>trans('setting.basic.close')])->default(1);
            $this->radio('sitePageGray', trans('setting.basic.site_page_gray'))->options(['0'=>trans('setting.basic.close'),'1'=>trans('setting.basic.home'),'2'=>trans('setting.basic.whole_station')])->default(0);

        });
        $this->tab(trans('setting.basic.upload_settings'), function () {
            $this->radio('ftpType', trans('setting.basic.ftpType'))
                ->when(1, function (Form $form) {
                    $form->text('aliossAccessId',  trans('setting.basic.accessKeyID'))->help(trans('setting.basic.accessKeyID_msg'));
                    $form->text('aliossAccessKey',  trans('setting.basic.accessKeySecret'))->help(trans('setting.basic.accessKeySecret_msg'));
                    $form->text('aliossEndpoint',  trans('setting.basic.endPoint'))->help(trans('setting.basic.endPoint_msg'));
                    $form->text('aliossBucket',  trans('setting.basic.bucket'))->help(trans('setting.basic.bucket_msg'));
                    $form->text('aliossHosts',  trans('setting.basic.alioss_hosts'))->help(trans('setting.basic.hosts_msg'));
                })
                ->when(2, function (Form $form) {
                    $form->text('KodoAccessKey', trans('setting.basic.AccessKey'));
                    $form->text('KodoSecretKey', trans('setting.basic.SecretKey'));
                    $form->text('KodoBucket', trans('setting.basic.KodoBucket'));
                    $form->text('KodouUrl', trans('setting.basic.KodouUrl'))->help(trans('setting.basic.hosts_msg'));
                })
                ->when(3, function (Form $form) {
                    $form->text('cos_secretid', trans('setting.basic.SecretId'));
                    $form->text('cos_secretkey', trans('setting.basic.SecretKey'));
                    $form->text('cos_region', trans('setting.basic.cos_region'));
                    $form->text('cos_bucket', trans('setting.basic.cos_bucket'));
                })
                ->when(0, function (Form $form) {
                    $form->text('attachUrl', trans('setting.basic.attachUrl'));
                    $form->text('photoType', trans('setting.basic.photoType'));
                    $form->text('photoSize', trans('setting.basic.photoSize'));
                    $form->text('videoType', trans('setting.basic.videoType'));
                    $form->text('videoSize', trans('setting.basic.videoSize'));
                    $form->text('audioType', trans('setting.basic.audioType'));
                    $form->text('audioSize', trans('setting.basic.audioSize'));
                    $form->text('fileType', trans('setting.basic.fileType'));
                    $form->text('fileSize', trans('setting.basic.fileSize'));
                    $form->text('is_multiupload', trans('setting.basic.is_multiupload'));
                    $form->text('ffmpeg', trans('setting.basic.ffmpeg'));
                    $form->text('videoCompress', trans('setting.basic.videoCompress'));
                    $form->text('openPhotoLog', trans('setting.basic.openPhotoLog'));
                })
                ->options(['0' => trans('setting.basic.local'), '1' => trans('setting.basic.oss'), '2' => trans('setting.basic.Kodo'), '3' => trans('setting.basic.cos')])->default('0');

        });
        $this->tab(trans('setting.basic.api_safe_settings'), function () {
            $this->text('AppCode', trans('setting.basic.AppCode'));

        });
    }

    /**
     * The data of the form.
     *
     * @return array $data
     */
    public function data()
    {
        $datas = SystemSettingModel::pluck('value', 'key');
        return $datas['system_basic'];
    }


}

